Foundation of Machine Learning CSCN8010¶

Lab 2 Task (Showing graph with Matplotlib, Seaborn and Plotly)¶

The follow table describes the type of Graphs displayed on this page

Package Name Graph Type
Matplotlib violinplot
Seaborn Scatterplot with continuous hues and sizes
Plotly Scatter plots with Plotly Express

Matplotlib(A violinplot) Click here to view this plot on the Matplotlib website

In [3]:
import matplotlib.pyplot as plt
import numpy as np


plt.style.use('_mpl-gallery')

# make data:
np.random.seed(10)
D = np.random.normal((3, 5, 4), (0.75, 1.00, 0.75), (200, 3))

# plot:
fig, ax = plt.subplots()

vp = ax.violinplot(D, [2, 4, 6], widths=2,
                   showmeans=False, showmedians=False, showextrema=False)
# styling:
for body in vp['bodies']:
    body.set_alpha(0.9)
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
       ylim=(0, 8), yticks=np.arange(1, 8))

plt.show()

Seaborn(Scatterplot with continuous hues and sizes) Click here to view this plot on the Seaborn website

In [2]:
import seaborn as sns
sns.set_theme(style="whitegrid")

# Load the example planets dataset
planets = sns.load_dataset("planets")

cmap = sns.cubehelix_palette(rot=-.2, as_cmap=True)
g = sns.relplot(
    data=planets,
    x="distance", y="orbital_period",
    hue="year", size="mass",
    palette=cmap, sizes=(10, 200),
)
g.set(xscale="log", yscale="log")
g.ax.xaxis.grid(True, "minor", linewidth=.25)
g.ax.yaxis.grid(True, "minor", linewidth=.25)
g.despine(left=True, bottom=True)
Out[2]:
<seaborn.axisgrid.FacetGrid at 0x7fadb5b8e230>

Plotly (Scatter plots with Plotly Express) Click here to view this plot on the Plotly website

In [9]:
import plotly.express as px
import plotly.graph_objects as go
from sklearn.linear_model import LinearRegression



plotly.offline.init_notebook_mode()


df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
fig.show()

This page was built by Norbert Osi Athekame

Alt text

alt text for screen readers

MarineGEO circle logo